#include "normalnode.h"
#include <qmath.h>

NormalNode::NormalNode(double val):
        Node(val)
{
    varianceNode = -1;
    meanNode  = -1;
}

NormalNode::NormalNode(QString lbl, double val, double sd, Node * meanNode, Node * varianceNode, bool observed):
        Node(lbl, val, sd, observed)
{
    setMeanNode(meanNode);
    setVarianceNode(varianceNode);
}

bool NormalNode::inRange(double v)
{
    return true;
}

void NormalNode::setMeanNode(Node * node)
{
    meanNode = addParentNode(node);
}

void NormalNode::setVarianceNode(Node * node)
{
    varianceNode = addParentNode(node);
}

double NormalNode::computeLogLikelihood()
{
    double mean = parents->at(meanNode)->getValue();
    double x    = getValue();
    double std  = sqrt(parents->at(varianceNode)->getValue());

    //if(std <= 0.0)
      //  return 0.0;

    double p    = gsl_ran_gaussian_pdf(x - mean,
                                       std);   

    return VALID_LOG(p);
}
